import minus,{add} from "./add";
// console.log(add(2,2));

// import("./add")
// .then(res=>{
//     console.log(res);
//     console.log(res.default(3,7));
// })

import React, { Suspense } from "react"
import Error from "./Error" //引入异常捕获的组件
console.log(add(2,2));
console.log(minus(10,3));
let dynamicCom = () => new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(import("./pages/My"))
        // reject("网络错误了啦")
    }, 2000)
})
//组件懒加载(按需加载)
let My = React.lazy(dynamicCom);
//配合另一个组件 Suspense 用于降级ui
//声明一个降级的页面结构
let fallbackUI = <h1>正在加载...</h1>
class LazyCom extends React.Component {
    render() {
        return (
            <fieldset>
                <legend>懒加载组件</legend>
                <Error>
                    <Suspense fallback={fallbackUI}>
                        <My />
                    </Suspense>
                </Error>
            </fieldset>
        )
    }
}

export default LazyCom